package com.shigen.demo.lambda;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @author shigenfu
 * @date 2023/10/6 2:56 下午
 */
public class Demo {

    public static void main(String[] args) {

        // getSum();
        // filterTest();
        covertTest();

    }

    private static void covertTest() {
        List<String> names = Arrays.asList("Alice", "Bob", "Charlie");
        List<String> uppercaseNames = names.stream()
            .map(String::toUpperCase)
            .collect(Collectors.toList());
        System.out.println(uppercaseNames);
    }

    private static void filterTest() {
        String name = "";
        name = Optional.ofNullable(name)
            .filter(n -> n.length() > 0)
            .orElse("Stranger");
        System.out.println("Hello, " + name);
    }

    private static void getSum() {
        List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
        int sum = numbers.stream().reduce(0, Integer::sum);
        System.out.println(sum);
    }

}
